package cn.snoworld.entity.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.Arrays;

@Component
@Slf4j
public class ArticleMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("start insert fill ....");

         System.out.println(Arrays.toString(metaObject.getSetterNames()));

        this.strictInsertFill(metaObject, "creationTime", LocalDateTime::now, LocalDateTime.class);
        this.strictInsertFill(metaObject, "modificationTime", LocalDateTime::now, LocalDateTime.class);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("start update fill ....");

        this.strictInsertFill(metaObject, "modificationTime", LocalDateTime::now, LocalDateTime.class);
    }
}
